<template>
  <div class="cardChange">
    <el-collapse v-model="activeNames1">
      <el-collapse-item title="标签页设置" name="1">
        <ul class="card-list">
          <li :class="[current==i?'curr':'']" v-for="(v,i) in styles.cardList" :key="i">
            <div @click="current=i,radio=''">
              <div>
                <svg style="font-size:20px;color:#B8B9BD" class="icon" aria-hidden="true">
                  <use xlink:href="#iconcaidan" />
                </svg>
              </div>
              <span>{{v.name}}</span>
            </div>
            <i @click.stop="deleteProduct(i)" style="color:#ff3c29" class="el-icon-delete"></i>
          </li>
        </ul>
        <el-button @click="addProductList" size="small" style="width:100%" plain>
          <i class="el-icon-plus"></i>
          <span>添加</span>
        </el-button>
      </el-collapse-item>
    </el-collapse>
    <el-collapse v-model="activeNames2">
      <el-collapse-item title="选项设置" name="2">
        <ul class="content-list">
          <li>
            <span>选择商品：</span>
            <div>
              <el-radio
                @click.native="addProduct(v.name)"
                style="width:60px"
                v-for="(v,i) in productList"
                :key="i"
                v-model="radio"
                :label="i"
              >{{v.name}}</el-radio>
            </div>
          </li>
          <li>
            <span>文字颜色：</span>
            <div>
              <colorSetting v-model="styles.colorWord" :originColor="styles.colorWord" initColor="#999"></colorSetting>
            </div>
          </li>
          <li>
            <span>选择颜色：</span>
            <div>
              <colorSetting v-model="styles.colorSelect" :originColor="styles.colorSelect" initColor="#2D8CF0"></colorSetting>
            </div>
          </li>
          <li>
            <span>背景颜色：</span>
            <div>
              <colorSetting v-model="styles.colorBg" :originColor="styles.colorBg" initColor="#fff"></colorSetting>
            </div>
          </li>
          <li>
            <span>标题：</span>
            <div>
              <el-input
                size="small"
                type="text"
                placeholder="请输入内容"
                v-model="styles.cardList[current].name"
                maxlength="10"
                show-word-limit
              />
            </div>
          </li>
          
          <li>
            <span>上间距：</span>
            <div>
              <edgeSetting v-model="styles.marginTop" unit="px" :max="50" :init="Number(styles.marginTop)"></edgeSetting>
            </div>
          </li>
          <li>
            <span>下间距：</span>
            <div>
              <edgeSetting v-model="styles.marginBottom" unit="px" :max="50" :init="Number(styles.marginBottom)"></edgeSetting>
            </div>
          </li>
          <li>
            <span>内部间距：</span>
            <div>
              <edgeSetting v-model="styles.marginRight" unit="px" :max="100" :init="Number(styles.marginRight)"></edgeSetting>
            </div>
          </li>
        </ul>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
import colorSetting from "../../comm/colorSetting";
import edgeSetting from "../../comm/edgeSetting";
export default {
  name: "cardChange",
  data() {
    return {
      activeNames1: "1",
      activeNames2: "2",
      current: 0,
      radio: "",
      productList: [
        { name: "最新消息" },
        { name: "最新商家" },
        { name: "最新资讯" },
        { name: "黄页" },
        { name: "顺风车" },
        { name: "求职信息" },
        { name: "招聘信息" },
        { name: "租房信息" },
      ],
    };
  },
  watch:{
    currentId(){
      console.log(this.styles,6666)
    },
  },
  computed: {
    ...mapState(["list", "currentId"]),
    styles() {
      return this.list[this.currentId].styles;
    },
  },
  components: {
    colorSetting,
    edgeSetting
  },
  methods: {
    addProduct(name) {
      this.styles.cardList[this.current].name = name;
    },
    addProductList() {
      this.styles.cardList.push({ name: "选项" });
    },
    deleteProduct(i) {
      if (this.styles.cardList.length == 1) {
        return false;
      }
      this.styles.cardList.splice(i, 1);
    },
  },
};
</script>


<style lang="less" scoped>
@import url("../../../assets/css/base.less");
.card-list {
  margin-bottom: 20px;
  border-radius: 4px;
  overflow: hidden;
  > .curr {
    border: 1px solid @mainColor;
  }
  > li:hover {
    border: 1px dashed @mainColor;
  }
  > li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #eee;
    padding-right: 10px;
    transition: all 0.5s;
    > div:nth-of-type(1) {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      > div:nth-of-type(1) {
        background-color: #f4f6f8;
        padding: 10px;
        margin-right: 20px;
      }
    }
  }
}
</style>
